<template>
  <div class="content-box">
    <nav-title title="解除劳动合同审批" :routerLink="routerLink" />
    <!-- 发起人基本信息 -->
    <div class="regulations-box">
      <div class="title">发起人基本信息</div>
      <div class="information">
        <p class="info-cell clearfix">
          <label class="label">姓名</label>
          <span class="value">{{baseData.cWfName}}</span>
        </p>
        <p class="info-cell clearfix">
          <label class="label">部门</label>
          <span class="value">{{baseData.cWfDeptdescr}}</span>
        </p>
        <p class="info-cell clearfix">
          <label class="label">岗位</label>
          <span class="value">{{baseData.cWfJcDescr}}</span>
        </p>
        <p class="info-cell clearfix">
          <label class="label">联系电话</label>
          <span class="value">{{baseData.cWfPhone}}</span>
        </p>
      </div>
    </div>
    <!-- 基本信息 -->
    <div class="regulations-box">
      <div class="title">基本信息</div>
      <div class="information">
        <p class="info-cell clearfix">
          <label class="label">员工ID</label>
          <span class="value">{{baseData.emplid}}</span>
        </p>
        <p class="info-cell clearfix">
          <label class="label">姓名</label>
          <span class="value">{{baseData.nameDisplay}}</span>
        </p>
        <p class="info-cell clearfix">
          <label class="label">部门</label>
          <span class="value">{{baseData.rsFullName}}</span>
        </p>
        <p class="info-cell clearfix">
          <label class="label">岗位</label>
          <span class="value">{{baseData.jobcodeDescr}}</span>
        </p>
        <p class="info-cell clearfix">
          <label class="label">职等</label>
          <span class="value">{{baseData.rsJobLevel}}</span>
        </p>
        <p class="info-cell clearfix">
          <label class="label">带教人</label>
          <span class="value">{{baseData.cName}}</span>
        </p>
        <p class="info-cell clearfix">
          <label class="label">入职日期</label>
          <span class="value">{{baseData.lastHireDt|dateFormat}}</span>
        </p>
        <p class="info-cell clearfix">
          <label class="label">申请日期</label>
          <span class="value">{{baseData.createdttm|dateFormat}}</span>
        </p>
        <p class="info-cell clearfix">
          <label class="label">联系电话</label>
          <span class="value">{{baseData.phone}}</span>
        </p>
      </div>
    </div>
    <!-- 流程信息 -->
    <div class="regulations-box">
      <div class="title">流程信息</div>
      <div class="information">
        <div class="info-cell">
          <label class="label">离职日期</label>
          <span class="value">{{terminationDt}}</span>
        </div>

        <div class="info-cell">
          <label class="label">离职详细原因</label>
          <span class="value">{{baseData.rsTerDetail}}</span>
        </div>
        <p class="info-cell clearfix">
          <label class="label">辞退说明</label>
          <span class="value">{{baseData.cOtherExplain}}</span>
        </p>
      </div>
    </div>
    <!--   流程图 -->
    <div class="regulations-box">
      <div class="title">流程图</div>
      <flow-chart :transNum="cTransactionNbr"></flow-chart>
    </div>
    <div class="regulations-box">
      <div class="info-label">审批意见</div>
      <div class="info-label-text">
        <textarea v-if="approved == '0'" placeholder="请在这里输入..." rows="5" v-model="cComments"></textarea>
        <textarea v-else readonly rows="5" v-model="cComments"></textarea>
      </div>
    </div>

    <div style="height: 50px"></div>
    <!-- 底部按钮 -->
    <div v-if="approved == '0'">
      <operation-btn @doOperate="doOperate" :cApprovalSw="cApprovalSw" :cDenySw="cDenySw" :cPushbackAllSw="cPushbackAllSw" :cAddSw="cAddSw"></operation-btn>
    </div>
  </div>
</template>

<script>
import { Datetime, Group, PopupPicker, PopupRadio } from 'vux'
import {
  getDissolution,
  getCompensateProcess,
  getCompensateApprove,
  getWastageDetailReason
} from '../../api/api'
import { json2Form } from '../../util/http'
import { dateFormat } from 'vux'
import operationBtn from './common/operationBtn'
import flowChart from './common/flowChart'

export default {
  components: {
    Datetime,
    Group,
    PopupPicker,
    PopupRadio,
    operationBtn,
    flowChart
  },
  created() {
    this.cTransactionNbr = this.$route.query.cTransactionNbr
    this.approved = this.$route.query.approved
    if (this.$route.query.approved == '0') {
      this.routerLink = 'TodoList'
    } else if (this.$route.query.approved == '1') {
      this.routerLink = 'DoneList'
    } else {
      this.routerLink = 'MyApplication'
    }
    //解除劳动合同审批信息
    this.getDissolutionInfo()
  },
  mounted() {
    //获取字典表信息
    //this.getDic()
  },
  data() {
    return {
      //返回需要跳转到哪个页面
      routerLink: '',
      //是否从已审批页面跳转过来
      approved: '0',
      //发起人信息
      cWfName: '',
      cWfDeptdescr: '',
      cWfJcDescr: '',
      cWfPhone: '',

      //基本信息
      emplid: '',
      nameDisplay: '',
      deptDescr: '',
      rsFullName: '',
      jobcodeDescr: '',
      rsJobLevel: '',
      lastHireDt: '',
      rsWklifBgnDt: '',
      cName: '',
      createdttm: '',
      phone: '',

      //流程信息
      terminationDt: '',
      cOtherExplain: '',

      date: '',
      rsTerDetail: '',

      //流程图信息
      processList: [],

      //按钮点击的参数
      cWfType: '',
      cTransactionNbr: '',
      cUserId: '',
      cComments: '',

      cApprovalSw: '',
      cDenySw: '',
      cPushbackAllSw: '',
      cAddSw: '',
      baseData: {}
    }
  },
  methods: {
    /*getDic() {
      getWastageDetailReason({ actionReason: this.reason })
        .then(res => {
          this.detailReasonList = []
          if (res && res.retCode === '000000') {
            for (let i = 0; i < res.retData.length; i++) {
              this.detailReasonList.push({
                value: res.retData[i].descr,
                key: res.retData[i].rsTerDetail
              })
            }
          }
        })
        .catch(res => {})
    },*/
    getDissolutionInfo() {
      let params = {
        cTransactionNbr: this.cTransactionNbr
      }
      getDissolution(params)
        .then(res => {
          if (res && res.retCode === '000000') {
            //发起人信息
            this.baseData = Object.assign({}, res.retData)
            // this.cWfName = res.retData.cWfName
            // this.cWfDeptdescr = res.retData.cWfDeptdescr
            // this.cWfJcDescr = res.retData.cWfJcDescr
            // this.cWfPhone = res.retData.cWfPhone
            // //基本信息
            // this.emplid = res.retData.emplid
            // this.nameDisplay = res.retData.nameDisplay
            // this.deptDescr = res.retData.deptDescr
            // this.rsFullName = res.retData.rsFullName
            // this.jobcodeDescr = res.retData.jobcodeDescr
            // this.rsJobLevel = res.retData.rsJobLevel
            // this.cName = res.retData.cName
            // this.lastHireDt = res.retData.lastHireDt
            // this.createdttm = res.retData.createdttm
            // this.phone = res.retData.phone
            //流程信息
            this.terminationDt = dateFormat(
              res.retData.terminationDt,
              'YYYY-MM-DD'
            )
            // this.cOtherExplain = res.retData.cOtherExplain
            // this.rsTerDetail = res.retData.rsTerDetail

            this.cApprovalSw = res.retData.cApprovalSw
            this.cDenySw = res.retData.cDenySw
            this.cPushbackAllSw = res.retData.cPushbackAllSw
            this.cAddSw = res.retData.cAddSw

            //审批信息
            this.cWfType = res.retData.cWfType
          } else {
            this.$vux.alert.show({
              title: '',
              content: res.retMsg
            })
          }
        })
        .catch(res => {
          this.$vux.alert.show({
            title: '警告',
            content: '网络异常，请稍后重试'
          })
        })
    },
    doOperate(actionType) {
      //同意，不同意，加签，退回
      let params = {
        c_WF_TYPE: this.cWfType,
        c_TRANSACTION_NBR: this.cTransactionNbr, //流程编号
        c_ACTION_TYPE: actionType,
        c_COMMENTS: this.cComments
      }

      if (actionType == 'AddStep') {
        this.$router.push({
          name: 'Visa',
          params: {
            c_TRANSACTION_NBR: this.cTransactionNbr,
            c_WF_TYPE: this.cWfType,
            c_COMMENTS: this.cComments,
            c_Link: 'Dissolution'
          }
        })
      } else {
        getCompensateApprove(json2Form(params))
          .then(res => {
            if (res && res.retCode === '000000') {
              let _this = this
              this.$vux.alert.show({
                title: '成功',
                content: '操作成功',
                onHide() {
                  _this.$router.push('/TodoList')
                }
              })
            } else {
              this.$vux.alert.show({
                title: '',
                content: res.retMsg
              })
            }
          })
          .catch(res => {
            this.$vux.alert.show({
              title: '警告',
              content: '网络异常，请稍后重试'
            })
          })
      }
    }
  }
}
</script>

<style type="text/scss" lang="scss">
@import '../../styles/staff.scss';
</style>
